$(document).on("click", '.J_link', function () {
    var h5Url = $(this).attr('data-url');
    var appUrl = $(this).attr('data-appurl');
    ctrip.jump({
        h5Url,
        appUrl
    })
})

//显示苹果免责申明
var ua = navigator.userAgent.toLowerCase() || '',
    isIOS = /(ios|iphone|ipad|ipod)/.test(ua);
if (isIOS) {
    document.getElementById('ios').style.display = 'block'
}
isAPP = /ctripwireless/.test(ua);

// window.onload = function () {
//     var offset = sessionStorage.getItem("offsetTop");
//     $(document).scrollTop(offset);
// }

// $(window).scroll(function () {
//     if ($(document).scrollTop() !== 0) {
//         sessionStorage.setItem("offsetTop", $(window).scrollTop());
//     }
// })


function renderTemplate(templateSelector, data, htmlSelector) {
    var t = $(templateSelector).html();
    var f = Handlebars.compile(t);
    var h = f(data);
    $(htmlSelector).html(h);
}

// 弹出框
$('.bg1 .huodo').click(() => {
    $('.shadow').css('display', 'block')
    $('.tankuang').css('display', 'block')
    $('html,body').addClass('overHiden');
})

// 关闭按钮
$('.tankuang .close').click(() => {
    $('.shadow').css('display', 'none')
    $('.tankuang').css('display', 'none')
    $('html,body').removeClass('overHiden');
})

$(document).ready(function () {
    $.ajax({
        url: 'https://m.ctrip.com/restapi/soa2/13503/queryProduct',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify({
            "paramList": [{
                "departCityID": 0,
                "productIDList": [
                    1703459,
                    2301665,
                    1341073,
                    104424510,
                    52177581,
                    50463024
                ],
                "businessType": "HOTEL",
            },]
        }),
        success: function (data) {
            function renderProduct(products) {
                $.each(data.products, function (index, item) {
                    var x = item.businessType;
                    var departCityID = item.departCityID;
                    $.each(item.productList, function (index2, item2) {
                        var idStr = "." + item2.productID;
                        if (item2.price == 0) {
                            $(idStr + " .symbol").hide()
                            $(idStr + " .since").hide()
                            $(idStr + " .price").html("实时计价");
                        }
                        else {
                            $(idStr + " .price").html(item2.price);
                        }
                        $(idStr + " .cover").attr("src", item2.imageUrl)
                        $(idStr + " .name").text(item2.name);
                        var index = item2.name.indexOf('(')
                        if (index !== -1) {
                            var name = item2.name.slice(0, index)
                            $(idStr + " .name").text(name);
                        }
                        $(idStr + " .J_link").attr("data-url", item2.h5Url);
                        $(idStr + " .J_link").attr("data-appurl", item2.appUrl);
                    });
                });
            }

            renderProduct(data.products);

        }
    });
    $.ajax({
        url: 'https://m.ctrip.com/restapi/soa2/13503/queryProduct',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify({
            "paramList": [{
                "departCityID": 0,
                "productIDList": [
                    142571,
                    55304,
                    50612,
                    140500,
                    70409,
                    3435410
                ],
                "businessType": "GTTD",
            },]
        }),
        success: function (data) {
            function renderProduct(products) {
                $.each(data.products, function (index, item) {
                    var x = item.businessType;
                    var departCityID = item.departCityID;
                    $.each(item.productList, function (index2, item2) {
                        var idStr = "." + item2.productID;
                        if (item2.price == 0) {
                            $(idStr + " .symbol").hide()
                            $(idStr + " .since").hide()
                            $(idStr + " .price").html("实时计价");
                        }
                        else {
                            $(idStr + " .price").html(item2.price);
                        }
                        $(idStr + " .cover").attr("src", item2.imageUrl)
                        $(idStr + " .name").text(item2.name);
                        var index = item2.name.indexOf('(')
                        if (index !== -1) {
                            var name = item2.name.slice(0, index)
                            $(idStr + " .name").text(name);
                        }
                        $(idStr + " .J_link").attr("data-url", item2.h5Url);
                        $(idStr + " .J_link").attr("data-appurl", item2.appUrl);
                    });
                });
            }

            renderProduct(data.products);

        }
    });
    $.ajax({
        url: 'https://m.ctrip.com/restapi/soa2/13503/queryProduct',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify({
            "paramList": [{
                "departCityID": 1008,
                "productIDList": [
                    36702795,
                    35481537,
                    35313920,
                    37187795,
                    37202769,
                    37226253
                ],
                "businessType": "TOUR",
            },]
        }),
        success: function (data) {
            function renderProduct(products) {
                $.each(data.products, function (index, item) {
                    var x = item.businessType;
                    var departCityID = item.departCityID;
                    $.each(item.productList, function (index2, item2) {
                        var idStr = "." + item2.productID;
                        if (item2.price == 0) {
                            $(idStr + " .symbol").hide()
                            $(idStr + " .since").hide()
                            $(idStr + " .price").html("实时计价");
                        }
                        else {
                            $(idStr + " .price").html(item2.price);
                        }
                        $(idStr + " .cover").attr("src", item2.imageUrl)
                        $(idStr + " .name").text(item2.name);
                        var index = item2.name.indexOf('(')
                        if (index !== -1) {
                            var name = item2.name.slice(0, index)
                            $(idStr + " .name").text(name);
                        }
                        $(idStr + " .J_link").attr("data-url", item2.h5Url);
                        $(idStr + " .J_link").attr("data-appurl", item2.appUrl);
                    });
                });
            }

            renderProduct(data.products);

        }
    });
})